-
Notifications
You must be signed in to change notification settings - Fork 964
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(rax_tree): Fix crash caused by element destruction in RaxTreeMap #4228
base: main
Are you sure you want to change the base?
fix(rax_tree): Fix crash caused by element destruction in RaxTreeMap #4228
Conversation
fixes dragonflydb#4172 Signed-off-by: Stepan Bagritsevich <[email protected]>
Can you please explain what the problem is in the PR description? |
V* ptr = &(*it).second; | ||
std::allocator_traits<decltype(alloc_)>::destroy(alloc_, ptr); | ||
alloc_.deallocate(ptr, 1); | ||
while (true) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two things that concern me here:
- Looking at how
raxRecursiveFree
is implemented it callsfree_callback(raxGetData(n)
and what I introduced before seems to be on par in that respect becauseV* ptr = &(*it).second;
is actually the result ofraxGetData(n)
. - Since we can reproduce this we should also include an isolated test to assert the root cause of the issue (my mistake not to suggest this earlier)
I would like to understand why deleting the result of raxGetData(n)
result in segfault.
P.s. I also checked what Valkey is doing and indeed they use free_callback
(they don't iterate like we do) but let's make sure we understand this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
raxFree passes NULL callback to the raxResursiveFree
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it's not called there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@BagritsevichStepan do you know how to reproduce this?
fixes #4172
This is the simplest solution. However, I propose a different solution that will invoke
raxFreeWithCallback
. The problem is that this will require a capturing lambda, as we need to passalloc_
. Therefore, we need to copy and update theraxFreeWithCallback
method for capturing lambdas.Additionally, I believe that the
SeekIterator
should be removed, as it seems the issue was caused by it